function [shadow_bw] = shadowDetection(curr, bg, ALPHA, BETA, S_THR, H_THR)
%--------------------------------------------------------------------------
% shadow Detection Function, computes all shadows that are not in the background.
% does this by thresholding HSV color (implemented like http://dali.mty.itesm.mx/~autonomos/Navdyn/node11.html)
%--------------------------------------------------------------------------
% @Parameters:
%               curr  ... current frame
%               bg    ... background frame
%               diff  ... difference image of current and backgound frame
%               ALPHA ... threshold to avoid noise
%               BETA  ... threshold to detect shadow by brightness(<1)
%               S_THR ... threshold for saturation(all above is not shadow)
%               H_THR ... threshold for hue(all above is no shadow)
%    @Returns:
%               shadow_bw   ... black/white image of shadows (shadows are black)
%--------------------------------------------------------------------------
currHSV = rgb2hsv(curr);
bgHSV = rgb2hsv(bg);
size_curr = size(curr);
shadow_bw = ones(size_curr(1), size_curr(2));
%traverses every pixel and checks if it is darker, as the backgound pixel.
%if it is, then it is checked if the hue and the saturation does not
%deviate too much from the the background. In that case shadow is detected.
for i=1:size_curr(1)
    for j=1:size_curr(2)
        absDiffH = abs(currHSV(i,j,1)-bgHSV(i,j,1))
        diffS = currHSV(i,j,2)-bgHSV(i,j,2)
        relationCurrBgV = double(currHSV(i,j,3))/double(bgHSV(i,j,3))
        
        if      ALPHA <= relationCurrBgV && relationCurrBgV <= BETA && diffS <= S_THR && absDiffH <= H_THR
            shadow_bw(i,j) = 0;
        end
    end
end
end
